<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="/WEB-INF/page-base.tld" prefix="w"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML xmlns="http://www.w3.org/1999/xhtml">
  <head>
  	<%@ include file="/platform/style.jsp"%>
	<script>
	$(function(){
		window.setTimeout(receiveImm,5000);
	})
	function imm_toSend(){
		var div=$("#Imm_List_div");
		var html=window.frames["Imm_HtmlEdit"].getHtmlValue();
		if(html.length>0){
			document.all.content.value=html;
			html="<div class='imm_li'><div class='imm_titlebg'><span class='imm_title'><a href='javascript:;' class='imm_a'>"+document.all.userName.value+"</a></span><span class='imm_time' style='padding-left:4px;'>"+ChangeTimeToString(new Date())+"</span></div><div class='imm_content'>"+html+"</div></div>";
			div.append(html);
			window.frames["Imm_HtmlEdit"].setHtmlValue('');
			$w.doUrl(ctx+'/platform/message/imm/ImmPage@sendImm.page',$("form").serializeArray(),function(json){
				if(json.state=='error'){
					div.append("<div style='width:100%;color:red'>&nbsp;你刚才消息发送失败！</div>");
				}
			})
		}
	}
	function receiveImm(){
		$w.doUrl(ctx+'/platform/message/imm/ImmPage@receiveImmByUser.page?userId='+document.all.userId.value,{},function(json){
			var div=$("#Imm_List_div");
			if(json.data){
				$(json.data).each(function(i){
					if(window.parent.lastId=="")if(i==0)window.parent.lastId=this.id+"";
					if(this.tag=='1' || this.tag=='3')
						html="<div class='imm_li'><div class='imm_titlebg'><span class='imm_title'>系统消息</span><span class='imm_time' style='padding-left:4px;'>"+this.immTime+"</span></div><div class='imm_content'>"+this.content+"</div></div>";
					else
						html="<div class='imm_li'><div class='imm_titlebg'><span class='imm_title'><a href='javascript:;' class='imm_a'>"+this.formUser+"（"+this.formDept+"）</a></span><span class='imm_time' style='padding-left:4px;'>"+this.immTime+"</span></div><div class='imm_content'>"+this.content+"</div></div>";
					div.append(html);
				});
				var scrollTop = div[0].scrollHeight;
            	div.scrollTop(scrollTop);
			}
			window.setTimeout(receiveImm,5000);
		})
	}
	function ChangeTimeToString(DateIn)
{
    var Year=0;
    var Month=0;
    var Day=0;
    var Hour = 0;
    var Minute = 0;
    var CurrentDate="";

    //初始化时间
    Year      = DateIn.getYear();
    Month     = DateIn.getMonth()+1;
    Day       = DateIn.getDate();
    Hour      = DateIn.getHours();
    Minute    = DateIn.getMinutes();
    

    if (Month >= 10 )
    {
        CurrentDate = CurrentDate + Month + "-";
    }
    else
    {
        CurrentDate = CurrentDate + "0" + Month + "-";
    }
    if (Day >= 10 )
    {
        CurrentDate = CurrentDate + Day ;
    }
    else
    {
        CurrentDate = CurrentDate + "0" + Day ;
    }
    
     if(Hour >=10)
    {
        CurrentDate = CurrentDate + " " + Hour ;
    }
    else
    {
        CurrentDate = CurrentDate + " 0" + Hour ;
    }
    if(Minute >=10)
    {
        CurrentDate = CurrentDate + ":" + Minute ;
    }
    else
    {
        CurrentDate = CurrentDate + ":0" + Minute ;
    }      
    return CurrentDate;
}
function showhistory(){
		window.parent.$w.addTab({title:'消息记录',iconUrl:ctx+'/platform/UI/style/blue/images/script.png',href:ctx+'/platform/message/imm/ImmPage@showHistoryImm.page?userId='+document.all.userId.value,fresh:true});
}
	</script>
<body class="easyui-layout">
  	<div data-options="region:'center',border:false">
  		<div class="easyui-layout" data-options="fit:true">
  			<div data-options="region:'center'" id="Imm_List_div">
  			</div>
	  		<div data-options="region:'south',split:true" style="height:144px">
			<div class="easyui-layout" data-options="fit:true">
				<div data-options="region:'center',border:false">
					<iframe name="Imm_HtmlEdit" src="<%=path %>/platform/message/imm/editor.jsp" width="100%" height="100%" frameborder="0" scrolling="no"></iframe>
				</div>
				<div data-options="region:'south',border:false" style="height:31px;" class="imm-buttonBar">
					<form name="Imm_form" action="" method="post"><input name="content" type="hidden"><w:hidden bind="userId"/><w:hidden bind="userName"/></form>
					<a href="#" class="easyui-linkbutton" iconCls="" onclick="showhistory()" data-options="iconUrl:'<%=path %>/platform/UI/style/blue/images/script.png'">消息记录</a>&nbsp;<a href="#" class="easyui-linkbutton" iconCls="icon_cancel" onclick="window.parent.$w.closeCurrWin()"> 关闭 </a>&nbsp;<a href="#" class="easyui-linkbutton" data-options="iconUrl:'<%=path %>/platform/UI/style/blue/images/email_go.png'" onclick="imm_toSend()"> 发送 </a>
				</div>
			</div>
		</div>
	</div>
	</div>
	<div data-options="region:'east',split:true,border:true" style="width:130px;background:#D6DFE6">
		<table width="100%"  height="100%">
			<tr>
				<td height="115" align="center"><img src="<%=path %>/platform/message/icon/head.png" style="border:1px solid #cccccc"></td>
			</tr>
			<tr>
				<td valign="top">
					<table align="center">
					<tr><td style="font-size:12px;">姓名：</td><td style="font-size:12px;"><w:write bind="userName"/></td></tr>
					<tr><td style="font-size:12px;">电话：</td><td style="font-size:12px;"></td></tr>
					</table>
				</td>
			</tr>
			<tr>
				<td height="137" align="center" style="border-top:1px solid #cccccc"><img src="<%=path %>/platform/message/icon/head.png" style="border:1px solid #cccccc"></td>
			</tr>
		</table>
	</div>
</body>
</html>